local skel = fk.CreateSkill{
  name = "kt_st__daizu",
}

Fk:loadTranslationTable{
  ["kt_st__daizu"] = "代俎",
  [":kt_st__daizu"] = "结束阶段，你可以选择一名其他角色，其于其下个回合内使用的前三张即时牌结算后你摸一张牌，"..
  "若你摸满或未摸，你视为对其使用X张【决斗】（X为你选择其为“代俎”的次数）。",

  ["#kt_st__daizu"] = "代俎：你可以选择一名其他角色，其于其下个回合内使用的前三张即时牌结算后你摸一张牌",
  ["@@kt_st__daizu"] = "代俎",

  ["$kt_st__daizu1"] = "宇内竖小，今已荡平，当论诸君功最。",
  ["$kt_st__daizu2"] = "高奴欲夺事于我，望晋王不吝翼臂，素愿为王争龙。",
  ["$kt_st__daizu3"] = "普天帝杨，国事则家事，何为不干？",
  ["$kt_st__daizu4"] = "加勋业，表金匾，万事不究。",
  ["$kt_st__daizu5"] = "用过其养，此逆乱之征。",
  ["$kt_st__daizu6"] = "老夫观你甚多，果然为一狼狈。",
}

skel:addEffect(fk.EventPhaseStart, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player.phase == Player.Finish
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = room:getOtherPlayers(player, false),
      skill_name = skel.name,
      prompt = "#kt_st__daizu",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, skel.name)
    player:broadcastSkillInvoke(skel.name,math.random(1,2))
    local to = event:getCostData(self).tos[1]
    room:setPlayerMark(to,"@@kt_st__daizu",4)
    room:addPlayerMark(to,"kt_st__daizu_his",1)
  end,
})

skel:addEffect(fk.TurnEnd, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target:getMark("@@kt_st__daizu") > 0 and target:getMark("kt_st__daizu_his") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local use = target:getMark("@@kt_st__daizu") == 4 or target:getMark("@@kt_st__daizu") == 1
    room:setPlayerMark(target,"@@kt_st__daizu",0)
    if not use then return end
    room:notifySkillInvoked(player, skel.name)
    player:broadcastSkillInvoke(skel.name,math.random(5,6))
    local numb = target:getMark("kt_st__daizu_his")
    for i = 1,numb do
      local card = Fk:cloneCard("duel")
      if not (player.dead or target.dead) and player:canUseTo(card,target) then
        card.skillName = skel.name
        room:useCard({
          from = player,
          card = card,
          tos = {target}
        })
      end
    end
  end,
})

skel:addEffect(fk.CardUseFinished, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target:getMark("@@kt_st__daizu") > 1 and (data.card.type == Card.TypeBasic or data.card:isCommonTrick())
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, skel.name)
    player:broadcastSkillInvoke(skel.name,math.random(3,4))
    room:addPlayerMark(target,"@@kt_st__daizu",-1)
    room:drawCards(player,1,skel.name)
  end,
})

return skel